import greenfoot.*;  // (World, Actor, GreenfootImage, Greenfoot and MouseInfo)

/**
 * Write a description of class HealthBar here.
 * 
 * @author (your name) 
 * @version (a version number or a date)
 */
public class HealthBar extends Actor
{
    private int health;
    private Timer timer=new Timer();
    
    public HealthBar()
    {
        health=100;
        setImage("healthbar100.png");
        timer.reset();
    }
    
    public void act() 
    { 
        timer.tick();
        
        if(health>10)
        {
            setLocation(110,130);
            timer.reset();
        }
        else
        
        if(health==10)
        {
            if(getY()>130)
            {
                if(!timer.wait(100))
                setLocation(110,125);
            }
            else    
                if(!timer.wait(100))
                setLocation(110,135);
        }
    }    
    
    public void updateImage(int h)
    {
        GameWorld world=(GameWorld)getWorld();
        Player player=world.getPlayer();
        health=h;
        
        if(h>0)
        setImage("healthbar"+health+".png");
        else
        setImage("healthbar0.png");
        
            
    }
}
